home *** CD-ROM | disk | FTP | other *** search
/ Network Supervisor's Toolkit / Network Supervisor's Toolkit.iso / tools / mdxdos23 / server.c < prev    next >
C/C++ Source or Header  |  1996-07-10  |  6KB  |  265 lines

  1. #include    "multix.h"
  2. #include    <stdio.h>
  3. #include    <stdlib.h>
  4. #include    <string.h>
  5. #include    <time.h>
  6.  
  7. #include    "appl.h"
  8. TMdxProcId    MyId;
  9.  
  10. void    ApplCallReqReceived(
  11. TMdxEvent    *Event
  12. )
  13. {
  14.     /*
  15.     Event->ProcId    -    Holds the calling process id.
  16.     Event->Password -    Holds the password used.
  17.     */
  18.     printf("Call Request from Process (%ld)\n",Event->ProcId);
  19.  
  20.     MdxAcceptProcess(Event->ProcId,(void *)0);
  21. }
  22.  
  23.  
  24. void    ApplSendMsgCompleted(
  25. TMdxEvent    *Event
  26. )
  27. {
  28.     TMdxSRMsgInfo        *MsgInfo;
  29.  
  30.     /*
  31.     "Event->Data"    holds the information abount the Message we sent.
  32.     */
  33.  
  34.     MsgInfo =    (TMdxSRMsgInfo    *)Event->Data;
  35.     switch(MsgInfo->Sent.MsgCode)
  36.     {
  37.         case    ApplGetTimeReplyCode    :
  38.         {
  39.             printf("Time Sent - Error = %d\n",Event->Error);
  40.         }
  41.         break;
  42.         case    ApplTextReplyMsgCode    :
  43.         {
  44.             printf("TextReply Sent - Error = %d\n",Event->Error);
  45.         }
  46.         break;
  47.         default                     :    break;
  48.     }
  49. }
  50.  
  51.  
  52. void    ApplTextDataReceived(
  53. TMdxSRMsgInfo  *MsgInfo
  54. )
  55. {
  56.     TBufSize    CountRead;
  57.     TMdxError    Result;
  58.     UInt8        Buf[80];
  59.     Int8Ptr     ReplyText    =    "This Is a Reply From the Server";
  60.  
  61.  
  62.     printf("Text Message Received - Size = %ld\n",MdxMsgSizeGet(MsgInfo->Received.Msg));
  63.     while (    (CountRead    =    MdxMsgRead(    MsgInfo->Received.Msg,
  64.                                             Buf,
  65.                                             sizeof(Buf)
  66.                                             ))    >    0    )
  67.     {
  68.         if (    fwrite(Buf,1,CountRead,stdout)    !=    CountRead    )
  69.         {
  70.             printf("Msg Write Failure\n");
  71.             MdxReply(MsgInfo,ApplErrWriteFileError);
  72.             return;
  73.         }
  74.     }
  75.     Result = MdxReplyWithData(    MsgInfo,                /*    Original Msg    */
  76.                             MdErrNoError,            /*    No Error Reply    */
  77.                             (UInt8Ptr)ReplyText,    /*    Data            */
  78.                             (TBufSize)strlen(ReplyText),        /*    Data Size        */
  79.                             ApplTextReplyMsgCode,    /*    Msg Code        */
  80.                             0,                        /*    Priority        */
  81.                             MdxSendReliable,        /*    Send Attributes    */
  82.                                                     /*    Success/Failure    */
  83.                                                     /*    Report            */
  84.                             0,                        /*    No ReqSeq        */
  85.                             1000                    /*    10 Secs    Timeout    */
  86.                             );
  87.     printf("Msg Displayed Ok Result = %d\n",Result);
  88. }
  89.  
  90.  
  91. void    ApplReplyWithTime(
  92. TMdxSRMsgInfo  *MsgInfo
  93. )
  94. {
  95.     TMdxTime    CurrTime;
  96.     TMdxError    Result;
  97.     CurrTime    =    MdxGetTime();
  98.     Result =    MdxReplyWithData(    MsgInfo,                /*    Original Msg    */
  99.                             MdErrNoError,            /*    No Error Reply    */
  100.                             (UInt8Ptr)&CurrTime,    /*    Data            */
  101.                             sizeof(CurrTime),        /*    Data Size        */
  102.                             ApplGetTimeReplyCode,    /*    Msg Code        */
  103.                             0,                        /*    Priority        */
  104.                             MdxSendReliable,        /*    Send Attributes    */
  105.                                                     /*    Success/Failure    */
  106.                                                     /*    Report            */
  107.                             0,                        /*    No ReqSeq        */
  108.                             1000                    /*    10 Secs    Timeout    */
  109.                             );
  110.     printf("Sending Time : Result = %d\n",Result);
  111. }
  112.  
  113.  
  114. void    ApplNewMsgReceived(
  115. TMdxEvent    *Event
  116. )
  117. {
  118.     TMdxSRMsgInfo    *MsgInfo;
  119.  
  120.     /*
  121.     "Event->Data"    holds the information abount the new message.
  122.     */
  123.  
  124.     MsgInfo =    (TMdxSRMsgInfo    *)Event->Data;
  125.  
  126.     /*    First    thing is to check MsgCode of the new message    */
  127.  
  128.     switch(MsgInfo->Received.MsgCode)
  129.     {
  130.         case    ApplGetTimeMsgCode    :
  131.         {
  132.             ApplReplyWithTime(MsgInfo);
  133.         }
  134.         break;
  135.         case    ApplTextDataMsgCode :
  136.         {
  137.             ApplTextDataReceived(MsgInfo);
  138.         }
  139.         break;
  140.         default                     :    break;
  141.     }
  142. }
  143.  
  144.  
  145.  
  146.  
  147. void    ApplInitReceived(void)
  148. {
  149.     /*
  150.     You may choose to use onw or more links of the types specified.
  151.     Un comment the relevent "MdxOpenLink()".
  152.  
  153.     You may change the parameters for the links.
  154.     */
  155.  
  156.  
  157.     TMdxLinkParams    LinkParams;
  158.     memset(&LinkParams,0,sizeof(LinkParams));
  159.     strcpy(LinkParams.LinkName.Byte,"com2");
  160.     LinkParams.LinkType                =    MdxLinkTypeAsyncLocal;
  161.     LinkParams.ConnectMode            =    MdxConnectModeListen;
  162.     LinkParams.ConnectTimeout        =    0x7fffffff;
  163.     LinkParams.MaxConnectRetries    =    -1;
  164.     LinkParams.ConnectRetriesDelay    =    200;
  165.     LinkParams.LinkBaud             =    19200;
  166.     LinkParams.UseDlcFraming        =    True;
  167.     LinkParams.ImAliveInterval        =    400l;
  168.     LinkParams.MaxPollRetries        =    2;
  169.     LinkParams.L1MaxSendSize        =    256;
  170.     /*
  171.     MdxOpenLink(&LinkParams);
  172.     */
  173.     memset(&LinkParams,0,sizeof(LinkParams));
  174.     strcpy(LinkParams.LinkName.Byte,"MdxFs");
  175.     LinkParams.LinkType                =    MdxLinkTypeSpxIpx;
  176.     LinkParams.ConnectMode            =    MdxConnectModeListen;
  177.     LinkParams.ConnectTimeout        =    1000;
  178.     LinkParams.MaxConnectRetries    =    -1;
  179.     LinkParams.ConnectRetriesDelay    =    200;
  180.     LinkParams.UseDlcFraming        =    True;
  181.     LinkParams.MaxPollRetries        =    10;
  182.     LinkParams.L1MaxSendSize        =    500;
  183.     /*
  184.     MdxOpenLink(&LinkParams);
  185.     */
  186.  
  187.     memset(&LinkParams,0,sizeof(LinkParams));
  188.     strcpy(LinkParams.LinkName.Byte,"MdxFs");
  189.     LinkParams.LinkType                =    MdxLinkTypeNetBios;
  190.     LinkParams.ConnectMode            =    MdxConnectModeListen;
  191.     LinkParams.ConnectTimeout        =    0x7fffffffl;
  192.     LinkParams.ConnectRetriesDelay    =    300l;
  193.     LinkParams.L1MaxSendSize        =    1024;
  194.     LinkParams.MaxConnectRetries    =    -1l;
  195.     /*
  196.     MdxOpenLink(&LinkParams);
  197.     */
  198.  
  199. }
  200.  
  201.  
  202. void    cdecl    ApplEventHandler(
  203. TMdxEvent    *Event
  204. )
  205. {
  206.     switch(Event->Code)
  207.     {
  208.         case    MdxEventApplInit                :
  209.         {
  210.             ApplInitReceived();
  211.         }
  212.         break;
  213.         case    MdxEvDataMsgReceived        :
  214.         {
  215.             ApplNewMsgReceived(Event);
  216.         }
  217.         break;
  218.         case    MdxEvSendMsgCompleted        :
  219.         {
  220.             ApplSendMsgCompleted(Event);
  221.         }
  222.         break;
  223.         case    MdxEvCallReqReceived        :
  224.         {
  225.             ApplCallReqReceived(Event);
  226.         }
  227.         break;
  228.         case    MdxStdInAvailable                :
  229.         {
  230.             ApplShutdown    =    True;
  231.         }
  232.         break;
  233.         default                                 :    break;
  234.     }
  235. }
  236.  
  237.  
  238. Int cdecl    main(
  239. Int     Argc,
  240. Int8Ptr *Argv
  241. )
  242. {
  243.  
  244.     if (    Argc    <    2    )
  245.     {
  246.         printf("Usage : server <Proccess Id>\n");
  247.         return(5);
  248.     }
  249.     MyId    =    (TMdxProcId)atol(Argv[1]);
  250.     if (    MyId    <=    0    )
  251.     {
  252.         printf("Node Id Should be between 1 - %ld\n",0x7fffffffl);
  253.         return(0);
  254.     }
  255.  
  256.     MultiXStart(MyId,"Server",0,ApplEventHandler);
  257.  
  258.     printf("Type any key to stop the program...\n");
  259.     while (    ApplShutdown    ==    False    )
  260.     {
  261.         MultiXWaitEvent();
  262.     }
  263.     return(0);
  264. }
  265.